<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>对props进行类型限制</title>
</head>
<body>
<div id="container">

</div>
</body>
</html>


<!--引入react核心库-->
<script type="text/javascript" src="../Js/react.development.js"></script>
<!--引入react-dom库,用于支持react操作dom-->
<script type="text/javascript" src="../Js/react-dom.development.js"></script>
<!--引入babel库,用于将jsx转成js-->
<script type="text/javascript" src="../Js/babel.min.js"></script>
<!--引入prop-types库,用于将对props进行类型限制-->
<script type="text/javascript" src="../Js/prop-types.js"></script>


<script type="text/babel">//此处一定要写text/babel，将jsx转成js
class Form extends React.Component{
  render(){
    const {name,age,sex}=this.props
    return <div>
      <ul>
        <li>{name}</li>
        <li>{age}</li>
        <li>{sex}</li>
      </ul>
    </div>
  }
}

const Person={
  name:"张三",
  age:18,
  sex:"男"
}
// 对类式组件进行类型限制
Form.propTypes={
  name:PropTypes.string.isRequired,
  age:PropTypes.number.isRequired,
  sex:PropTypes.string.isRequired,
}

// 不传参的默认值
Form.defaultProps={
  name:'zs',
  age:18,
  sex:'男',
}

ReactDOM.render(<Form {...Person}/>,document.getElementById("container"))

</script>

